package com.itany.servlet;

import com.alibaba.fastjson.JSON;
import com.itany.entity.Account;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * Author：汤小洋
 * Date：2022-11-15 13:37
 * Description：<描述>
 */
@WebServlet("/jsonp")
public class JsonpServlet extends HttpServlet {

    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String callback = req.getParameter("callback"); // handle

        resp.setContentType("application/json;charset=utf8");
        PrintWriter out = resp.getWriter();

        Account account = new Account(1001, "aaa", "123", "汤姆");

        out.print(callback+"("+JSON.toJSONString(account)+")"); // handle(res)
        out.close();
    }
}
